<template>
	<view class="business-page">
		<view class="search">
			<u--input v-model="search" placeholder="搜索关键词" readonly prefixIcon="search"
				prefixIconStyle="font-size: 22px;color: #9799AA" shape="circle"
				placeholderStyle="color: #9799AA"></u--input>
			<view class="overlay" @click="$navTo.togo('/pages/index/keyword/sjindex')"></view>
		</view>
		<view class="tips">
			<view class="tips-title">
				欢迎商家入驻
			</view>
			<view class="tips-text">
				领取优惠入驻体验馆
			</view> 
		</view>
		<view class="use"> 
			<view class="use-item" v-for="(item,index) in useList" @click="$navTo.togo('/pages/business/classification/index?id=' + item.id + '&title='+item.name)" :key="index">
				<image :src="'https://m.lqvvvv.com'+item.image" mode=""></image> 
				<view class="use-text">
					{{item.name}}
				</view>
			</view>
		</view>
		<view class="join">
			<image @click="NoOpen" class="join-item" src="https://m.lqvvvv.com/images/organize/zuju.png" mode=""></image>
			<image @click="gomybuss" v-if="info != null&&info.approve_status == 1" class="join-item" src="https://m.lqvvvv.com/assets/static/business/store3.png" mode=""></image>
			<image @click="goJoin" v-else class="join-item" src="https://m.lqvvvv.com/assets/static/business/store2.png" mode=""></image>
		</view>
		<view class="location">
			<view class="location-text">
				{{city}}
			</view>
			<u-icon name="map" color="#2E314A" size="16"></u-icon>
		</view>
		<view class="shop">
			<view class="shop-item" v-for="(item,index) in list" :key="index" @click="goDetails(item.id)">
				<image :src="'https://m.lqvvvv.com'+item.avatar" mode="aspectFill"></image>
				<view class="shop-right">
					<view class="name">
						{{item.title}}
					</view>
					<view class="evaluate">
						<view class="score">
							{{item.points}}
						</view>
						<view class="evaluate-text">
							{{item.service_time}}
						</view>
					</view>
					<view class="comment">
						{{item.intro}}
					</view>
					<view class="distance">
						距您直线{{item.distance}}km {{item.address}}
					</view>
					<view class="benefit">
						<view class="benefit-item" v-if="x < 3" v-for="(i,x) in item.tags.split(',')" :key="x">
							{{i}}
						</view>
					</view>
					<view class="price">
						<view class="num">
							￥ <text>{{item.min_price}}</text>
						</view>
						<view>
							起
						</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" />
		</view>
		<!-- #ifdef MP-WEIXIN -->
		<!-- <u-tabbar :value="1" :fixed="true" :placeholder="true" activeColor="#5755F2" inactiveColor="#2E314A"
			:safeAreaInsetBottom="true">
			<u-tabbar-item text="首页" v-if="tabshow == 0" @click="gotaburl('首页')">
				<image style="width: 38rpx; height: 38rpx;" slot="active-icon" src="/static/tabbar/home1.png"></image>
				<image style="width: 38rpx; height: 38rpx;" slot="inactive-icon" src="/static/tabbar/home0.png"></image>
			</u-tabbar-item>
			<u-tabbar-item text="商家" @click="gotaburl('商家')">
				<image style="width: 38rpx; height: 38rpx;" slot="active-icon" src="/static/tabbar/business1.png">
				</image>
				<image style="width: 38rpx; height: 38rpx;" slot="inactive-icon" src="/static/tabbar/business0.png">
				</image>
			</u-tabbar-item>
			<u-tabbar-item text="消息" @click="gotaburl('消息')">
				<image style="width: 38rpx; height: 38rpx;" slot="active-icon" src="/static/tabbar/msg1.png"></image>
				<image style="width: 38rpx; height: 38rpx;" slot="inactive-icon" src="/static/tabbar/msg0.png"></image>
			</u-tabbar-item>
			<u-tabbar-item text="我的" @click="gotaburl('我的')">
				<image style="width: 38rpx; height: 38rpx;" slot="active-icon" src="/static/tabbar/my1.png"></image>
				<image style="width: 38rpx; height: 38rpx;" slot="inactive-icon" src="/static/tabbar/my0.png"></image>
			</u-tabbar-item>
		</u-tabbar> -->
		<!-- #endif -->
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				search: '',
				list: [],
				status: 'loadmore',
				useList: [],
				info:{}, 
				page:1,
				tabshow: 0
			}
		},
		computed: {
			...mapState({
				location: state => state.location,
				city: state => state.city
			})
		},
		onShow() {
			// #ifdef MP-WEIXIN
			this.showinfo()
			// #endif
			this.page = 1
			this.postlist() 
			let token = uni.getStorageSync("token") || '';
			if (token != '') {
				this.getApproveStatus()
			}
			
		},  
		onLoad() {
			this.getCategory()
			
		},
		onReachBottom() {
			this.page = this.page + 1
			this.status = 'loading';
			this.postlist()
		},
		methods: {
			gotaburl(name) {
				if (name == '首页') {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
				if (name == '商家') {
					uni.switchTab({
						url: '/pages/business/index'
					})
				}
				if (name == '消息') {
					uni.switchTab({
						url: '/pages/message/index'
					})
				}
				if (name == '我的') {
					uni.switchTab({
						url: '/pages/my/index'
					})
				}
			},
			showinfo() {
				let params = {
					// #ifdef APP
					name: 'hide_status',
					// #endif
					// #ifdef MP-WEIXIN
					name: 'miniapp_hide_status'
					// #endif
				}
				this.$Request({
					method: 'POST',
					url: '/api/index/getConfig',
					data: params,
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						this.tabshow = res.data
					}
				})
			},
			getApproveStatus() {
				let params = {
			
				}
				this.$Request({
					method: 'POST',
					url: '/api/user_shop/getApproveStatus',
					data: params,
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						this.info = res.data
					}
				})
			},
			getCategory(){
				this.$Request({
					method: 'POST',
					url: '/api/user_shop/getCategory',
					data: {},
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						this.useList = res.data
					}
				}) 
			},
			postlist() { 
				let params = {
					lat: this.location.latitude,
					lng: this.location.longitude,
					page: this.page,
					limit: 10
				}
				this.$Request({
					method: 'POST',
					url: '/api/user_shop/getList',
					data: params,
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						if (res.data.data.length < 10) {
							this.status = 'nomore';
						}
						if (this.page == 1) {
							this.list = res.data.data
						} else {
							this.list = [...res.data.data, ...this.list]
						}
					}
				})
			},
			NoOpen() {
				let token = uni.getStorageSync("token") || '';
				if (token != '') {
					// uni.showToast({
					// 	title:'暂未开放！',
					// 	icon:'none'
					// })
					uni.switchTab({
						url:'/pages/my/organize/index'
					})
					// let info = uni.getStorageSync('userinfo');
					// this.$navTo.togo('/pages/session-info/session-info', {
					// 	id: info.sessionInfo.id
					// })
				}else{
					uni.showModal({
						title: '提示',
						content: '请登录！体验完整功能！',
						confirmText:'去登录',
						success: function (res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.reLaunch({
									url:'/pages/login/index'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
			},
			gomybuss(){
				this.$navTo.togo('/pages/business/mybusiness/index')
			},
			goJoin() {
				let token = uni.getStorageSync("token") || '';
				if (token != '') {
					this.$navTo.togo('/pages/business/Join/index')
				}else{
					uni.showModal({
						title: '提示',
						content: '请登录！体验完整功能！',
						confirmText:'去登录',
						success: function (res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.reLaunch({
									url:'/pages/login/index'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
				
			},
			goDetails(id){
				this.$navTo.togo('/pages/business/details/index',{id:id})
			}
		}
	}
</script>
<style>
	.u-border {
		border: 1px solid #ffffff !important;
		/* 设置边框颜色为蓝色 */
	}

	page {
		background-color: #F7F8FC;
	}
</style>
<style lang="scss" scoped>
	.business-page {
		min-height: 90vh;
		background-image: url('https://m.lqvvvv.com/assets/static/business/top-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 900rpx;
		padding: 60rpx 30rpx 30rpx 30rpx;

		.search {
			width: 100%;
			padding: 30rpx 0;
			position: relative;

			.overlay {
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				background-color: transparent;
				/* 或设置为rgba(0,0,0,0) */
				cursor: pointer;
				/* 添加手型光标 */
			}
		}

		.tips {
			padding: 60rpx 0;

			.tips-title {
				font-size: 50rpx;
				font-weight: bold;
				color: #000;
			}

			.tips-text {
				color: #2E314A;
				font-size: 28rpx;
				margin-top: 20rpx;
			}
		}

		.use {
			padding: 20rpx 20rpx 0;
			background-color: #ffffff;
			border-radius: 30rpx;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;
			margin-top: 30rpx;

			.use-item {
				width: 120rpx;
				margin-bottom: 30rpx;
				text-align: center;

				image {
					width: 80rpx;
					height: 80rpx;
				}

				.use-text {
					font-size: 24rpx;
					color: #000;
				}
			}
		}

		.join {
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;

			.join-item {
				width: 344rpx;
				height: 160rpx;
			}
		}

		.location {
			display: flex;
			align-items: center;
			margin-top: 20rpx;
			padding-left: 20rpx;

			.location-text {
				margin-right: 10rpx;
				color: #2E314A;
				font-size: 28rpx;
				font-weight: 700;
			}
		}

		.shop {
			.shop-item {
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;
				background-color: #ffffff;
				padding: 20rpx;
				border-radius: 30rpx;

				image {
					width: 35%;
					height: 298rpx;
					border-radius: 30rpx;
				}

				.shop-right {
					width: 60%;
					font-size: 24rpx;

					.name {
						font-weight: bold;
						font-size: 28rpx;
						color: #000;
					}

					.evaluate {
						display: flex;
						align-items: center;
						margin-top: 10rpx;

						.score {
							background-color: #5755F2;
							padding: 5rpx 10rpx;
							border-radius: 10rpx;
							font-size: 20rpx;
							font-weight: bold;
							color: #ffffff;
							border-bottom-right-radius: 20rpx;
						}

						.evaluate-text {
							margin-left: 10rpx;
							color: #2D2D2D;
						}
					}

					.comment {
						padding: 10rpx 0;
						color: #B76CF7;
					}

					.distance {
						color: #6D6D6D;
					}

					.benefit {
						display: flex;
						align-items: center;
						margin-top: 10rpx;

						.benefit-item {
							margin-right: 20rpx;
							padding: 3rpx 7rpx;
							border: 1rpx solid #5755F2;
							border-radius: 5rpx;
							text-align: center;
							color: #5755F2;
						}
					}


					.price {
						margin-top: 10rpx;
						display: flex;
						align-items: center;
						justify-content: right;
						color: #6D6D6D;

						.cancel {
							text-decoration: line-through;
						}

						.num {
							color: #FF5959;
							display: flex;
							align-items: center;
							padding: 0 5rpx;

							text {
								font-size: 36rpx;
								font-weight: bold;
							}
						}
					}
				}
			}
		}
	}
</style>